package actions;

import com.opensymphony.xwork2.ActionSupport;
import controllers.AbstractController;


public class DeleteFile extends ActionSupport {

	private static final long serialVersionUID = 1164809814839976523L;
	
	// -------------------------------------------------------------
	// Objects
	// -------------------------------------------------------------

	AbstractController controller = new AbstractController();

	private int idRender;
	private int idFile;
	
	// -------------------------------------------------------------
	// Methods
	// -------------------------------------------------------------

	public String execute() {
		System.out.println("..............Delete a file......");
		System.out.println("delete method called with " + idFile);
		String file_path;
		file_path = controller.deleteFilebyId(idFile);
		if ( file_path !=null){
			java.io.File file = new java.io.File(file_path);
			System.out.println(file.getName() + " is opened and it s in path="+file_path);
			if(file.delete()){
    			System.out.println(file.getName() + " is deleted!");
    		}else{
    			System.out.println("Delete operation is failed.");
    		}
			return SUCCESS;
		}
		else 
			return ERROR;
	}
	// setters and getters
	public int getIdFile() {
		return idFile;
	}
	public void setIdFile(int idFile) {
		this.idFile = idFile;
	}
	public int getIdRender() {
		return idRender;
	}
	public void setIdRender(int idRender) {
		this.idRender = idRender;
	}

}
